package view.gui {	
	import adobe.utils.CustomActions;
	import controller.ControllerManager;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	import flash.utils.getQualifiedClassName;
	import view.graph.GraphManager;
	import view.graph.GraphStates;
	import view.graph.states.GraphExpansionType;
	import view.GraphicPost;
	import view.GraphicPostRoot;
	import view.gui.components.TwoStatesButton;
	import view.ViewManager;
	/**
	 * ...
	 * @author Anthony
	 */	
	public class GuiManager
	{
		//------------------------------- statics ------------------------------\\
		private static const NAVIGATIONZONESWIDTH : int = 50;
		
		private static var _self : GuiManager = new GuiManager();
		
		//------------------------------ variables -----------------------------\\
		private var _graphic 						: Sprite;
		private var _graphicPostGui					: Object /*GraphicPostGui*/;
		
		//------------------------------ accessors -----------------------------\\
		public static function get self() 	: GuiManager 	{ return _self; }
		public function get graphic() 		: Sprite 		{ return _graphic; }
		
		//-------------------------- public functions --------------------------\\
		public function GuiManager()
		{			
			if (_self)
				throw new Error("GuiManager can only be accessed through GuiManager.self");
			else
			{
				_graphic 						= new Sprite();
				_graphicPostGui 				= new Object();
			}
		}
		
		public function init() : void
		{
			ViewManager.self.graphic.stage.addEventListener(MouseEvent.MOUSE_MOVE, onStageMouseMoove);
			
			var testButton : TwoStatesButton = new TwoStatesButton(	new Bitmap(new BitmapData(100, 20, false, 0xAA0000)), 
																	new Bitmap(new BitmapData(100, 20, false, 0x00AA00)));																	
			testButton.x = 500;
			testButton.addEventListener(MouseEvent.CLICK, clickTestButton);			
			_graphic.addChild(testButton);
			
			var testButton2 : TwoStatesButton = new TwoStatesButton(	new Bitmap(new BitmapData(100, 20, false, 0xAAAA00)), 
																		new Bitmap(new BitmapData(100, 20, false, 0x00AAAA)));																	
			testButton2.x = 500;
			testButton2.y = 25;
			testButton2.addEventListener(MouseEvent.CLICK, clickTestButton2);			
			_graphic.addChild(testButton2);			
			
			for (var graphicPostKey : String in GraphManager.self.graphGraphicPosts)
			{
				var currentGraphicPost : GraphicPost = GraphManager.self.graphGraphicPosts[graphicPostKey];
				if (getQualifiedClassName(currentGraphicPost) != getQualifiedClassName(GraphicPostRoot.self))
				{
					var graphicPostGui : GraphicPostGui = new GraphicPostGui(currentGraphicPost);				
					_graphicPostGui[currentGraphicPost.data.key] = graphicPostGui;
					graphicPostGui.update();
				}
			}
		}
		
		public function updateGraphicPostGui() : void
		{
			for (var graphicPostKey : String in _graphicPostGui)
			{
				_graphicPostGui[graphicPostKey].update();
			}
		}
		
		//------------------------- private functions --------------------------\\
		private function onStageMouseMoove(me : MouseEvent) : void
		{
			if (me.currentTarget.mouseX < NAVIGATIONZONESWIDTH)
				trace("left");
			else if (me.currentTarget.mouseX > (_graphic.stage.stageWidth - NAVIGATIONZONESWIDTH))
				trace("right");
				
			if (me.currentTarget.mouseY < NAVIGATIONZONESWIDTH)
				trace("top");
			else if (me.currentTarget.mouseY > (_graphic.stage.stageHeight - NAVIGATIONZONESWIDTH))
				trace("bottom");
		}
		
		private function clickTestButton(me : MouseEvent) : void
		{
			GraphStates.self.graphExpansionType = ((GraphStates.self.graphExpansionType == GraphExpansionType.CONDENSED) ? GraphExpansionType.EXTENDED : GraphExpansionType.CONDENSED);
		}
		
		private function clickTestButton2(me : MouseEvent) : void
		{
			
		}
		
		
	}
}